package com.vc.aha_server_event.service;


import com.vc.aha_server_event.dto.TravelProjectDto;
import com.vc.aha_server_event.entity.TravelProjectNum;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author pcy
 *
 * @date 2022/04/05
 */
@Service
public class TravelThroughProjectNumService {
    @Resource
    private MongoTemplate mongoTemplate;

    public void saveTravelProjectNum(Integer eventId, String time, Integer userId,Integer projectId){

        List<TravelProjectDto> travelProjectDtos = mongoTemplate.findAll(TravelProjectDto.class);
        int count = 0;
        for (TravelProjectDto travelProjectDto : travelProjectDtos){
            if(travelProjectDto.getTravelProjectNum().getUserId().equals(userId)){
                count = count + 1;
            }
        }
        TravelProjectNum travelProjectNum = new TravelProjectNum();
        travelProjectNum.setProjectId(projectId);
        travelProjectNum.setProjectNum(count);
        travelProjectNum.setUserId(userId);
        mongoTemplate.save(TravelProjectDto.builder().eventId(eventId).time(time).travelProjectNum(travelProjectNum).build());
    }

}
